import cv2
import numpy as np

img = cv2.imread('./picture/pic1.JPG')

def adjust_gamma(image, gamma=1.0):
    invGamma = 1.0 / gamma
    table = []
    for i in range(256):
        table.append(((i / 255.0) ** invGamma) * 255)
    table = np.array(table).astype("uint8")
    print(table)
    return cv2.LUT(image, table)

def localEqualHist(image):
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    clahe = cv2.createCLAHE(clipLimit=5, tileGridSize=(7,7))
    dst = clahe.apply(gray)

# gamma大于0和小于1的时候图像会比原图更暗
# gamma大于1的时候，图像会比原图更亮
img_gamma = adjust_gamma(img, 4.5)
print('宽 高 通道数：',img_gamma.shape[0],img_gamma.shape[1],img_gamma.shape[2])
# print(img_gamma)
# (b, g, r) = cv2.split(img_gamma)
# bH = cv2.equalizeHist(b)
# gH = cv2.equalizeHist(g)
# rH = cv2.equalizeHist(r)
# dat = cv2.merge((bH, gH, rH))
# cv2.imshow('dat', dat)
src=img_gamma
localEqualHist(src)
cv2.imshow("localEqualHist", src)

cv2.imshow("img", img)
cv2.imshow("img_gamma", img_gamma)
cv2.waitKey(0)
cv2.destroyAllWindows()